package com.manager.devicemanager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.manager.devicemanager.entity.Cramtest;
import com.manager.devicemanager.mapper.CramtestMapper;
import com.manager.devicemanager.service.ICramtestService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manager.devicemanager.vo.ComponentStatusRequestVO;
import com.manager.devicemanager.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wpf
 * @since 2025-09-25
 */
@Service
public class CramtestServiceImpl extends ServiceImpl<CramtestMapper, Cramtest> implements ICramtestService {
    @Autowired
    private  CramtestMapper cramtestMapper;


    @Override
    public List<Cramtest> getList(String dataSourceName, ComponentStatusRequestVO componentStatusRequestVO) {
        LambdaQueryWrapper<Cramtest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Cramtest::getBoardId, Integer.parseInt(componentStatusRequestVO.getBoardid()));
        queryWrapper.eq(Cramtest::getComponentId, componentStatusRequestVO.getComponentid());
        queryWrapper.between(Cramtest::getTimestamp,componentStatusRequestVO.getStartTime(),componentStatusRequestVO.getEndTime());
        return cramtestMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<Cramtest> getPage(String dataSourceName, PageVO<ComponentStatusRequestVO> pageVO) {
        IPage<Cramtest> page = new Page<>(pageVO.getPageNum(), pageVO.getPageSize());
        ComponentStatusRequestVO componentStatusRequestVO = pageVO.getCondition();
        LambdaQueryWrapper<Cramtest> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Cramtest::getBoardId, Integer.parseInt(componentStatusRequestVO.getBoardid()));
        queryWrapper.eq(Cramtest::getComponentId, componentStatusRequestVO.getComponentid());
        queryWrapper.between(Cramtest::getTimestamp,componentStatusRequestVO.getStartTime(),componentStatusRequestVO.getEndTime());
        return cramtestMapper.selectPage(page, queryWrapper);
    }


}
